package algorithm;

public class leetcode_209 {
    public int minSubArrayLen(int target, int[] nums) {
        int left=0;
        int right=0;
        int len=nums.length;
        int sum=nums[0];
        int step=0;
        while(left<len&&right<len){
            if(sum<target&&right<len-1){
                right++;
                sum+=nums[right];
            }
            else if(sum<target&&right==len-1){
                break;
            }
            else {
                if(step==0) step=len;
                step=(step<(right-left+1))?step:(right-left+1);
                sum-=nums[left];
                left++;
            }
        }
        return  step;
    }
}
